﻿using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Ipmce.RemoteVoting.Common.Tools
{
	public class PasswordCreator : IPasswordCreator
	{
		public string CreatePassword(string sms, byte[] dg2Data)
		{
			var hasher = new SHA1CryptoServiceProvider();
			return CreatePasswordFromHash(sms, hasher.ComputeHash(dg2Data));
		}

		public string CreatePasswordFromHash(string sms, byte[] dg2DataHash)
		{
			var data = Encoding.UTF8.GetBytes(sms).Concat(dg2DataHash).ToArray();
			var hasher = new SHA1CryptoServiceProvider();
			var result = hasher.ComputeHash(data);
			return Convert.ToBase64String(result);
		}
	}
}